package com.example.prom.dangwen.y2023.thread;

import lombok.SneakyThrows;

public class MyThread2 extends Thread {
    @SneakyThrows
    public void run() {
        while (true){
            // 检查当前线程是否被中断
            if (Thread.interrupted()) {
                System.out.println("线程被中断");
            } else {
                System.out.println("线程未被中断");
            }
            Thread.sleep(3000);
        }
    }

    public static void main(String[] args) {
        MyThread2 thread = new MyThread2();
        thread.start();

        // 中断线程
        thread.interrupt();
    }


}

